

//阻止事件冒泡
function stopNextEvent(evt){
    var e=(evt)?evt:window.event;
    if (window.event) {
        e.cancelBubble=true;// ie下阻止冒泡
    } else {
        //e.preventDefault();
        e.stopPropagation();// 其它浏览器下阻止冒泡
    }
}
// 列表的下拉更多
function dropdown(){ 
    $(".dropdown").on({
        click:function(obj,evt){
            if($(this).hasClass("on")){
                $(this).find("ul").stop().slideUp(10);
                $(this).removeClass("on")
            }else{
                var top =$(this).offset().top-$(window).scrollTop()+$(this).height()
                var left =$(window).width()-$(this).offset().left-$(this).width();
                $('.dropdown').find("ul").stop().slideUp(10);
                $(this).find("ul").css({"right":left+'px','top':top+'px'});
                $(this).find("ul").stop().slideDown(300);
            }
            stopNextEvent(evt)
        }
    })
    function hidedropdown(){
        $('.dropdown').find("ul").stop().slideUp(10);
        $('.dropdown').removeClass("on")
    }
    $("body").on("click", hidedropdown);
    document.addEventListener("touchmove", hidedropdown );
    $(window).scroll(hidedropdown)
}
dropdown()

$(".match_table .tips").prev().css({"padding-right":"0px"})

// 今天看了什么的js
function Date_doday() {
    let that = this;
  
    that.defaultIndex = 0;
    that.slide_ = '';
    that.getday_ = (day) => {
        let now_ = new Date(day);
        let w = now_.getDay();
        var w1 = ['日', '一', '二', '三', '四', '五', '六'];
        return w1[w];
    };
    that.slide = function () {
        if ($(".matchDatebox .swiper-container .swiper-slide").size() > 1) {
            that.slide_ =   new Swiper('.matchDatebox .swiper-container', {
                slidesPerView: 'auto',
                observer: true,  //开启动态检查器，监测swiper和slide
                observeParents:true,//修改swiper的父元素时，自动初始化swiper
                speed: 400,
            });
        }
    }
    that.slide();
    that.matchdata = function () {
        // let now = new Date('Mon Jan 07 2023 11:16:39 GMT+0800 (中国标准时间)');
        let now = new Date();
        let nowStr = now.getFullYear() + "-"
            + (now.getMonth() + 1 < 10 ? "0" + (now.getMonth() + 1) : now.getMonth() + 1) + "-"
            + (now.getDate() < 10 ? "0" + now.getDate() : now.getDate()) + "";
        $(" .matchDatebox .swiper-container .swiper-slide").each(function () {
            var time = $(this).find("a").attr("data-time");
            $(this).find("a span").text(time.substr(5, 5))
            $(this).find("a p").text("星期" + that.getday_(time));
            if (time === nowStr) {
                var text = $(this).find("a p").text();
                $(this).find("a p").text(text + "(今天)");
                that.index(this)
            }
            if($(".matchDatebox .swiper-container .swiper-slide.active").size()>0){
                that.index(".matchDatebox .swiper-container .swiper-slide.active")
            }
        })
    };
    that.index=function(obj){
        $(obj).addClass("now").siblings().removeClass('now');
        $(obj).index()<=3? that.defaultIndex = 0  : that.defaultIndex = $(obj).index()-3;;
        that.slide_.slideTo(that.defaultIndex,500, true);//
    };
    that.matchdata();
    // 今天看了什么的日期调用  
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#matchDate' //指定元素
            , showBottom: false
            , done: function (value, date, endDate) {
                // 这里是点击日历的选项
                $(".matchDatebox .swiper-container .swiper-slide").each(function () {
                    var time = $(this).find("a").attr("data-time");
                    if (time === value) {
                        that.index(this);
                    }
                })
            }
        });
    });
}
var Date_doday = new Date_doday();//实例化对象
